# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     tmp
   Description :
   Author :       'li'
   date：          2020/5/1
-------------------------------------------------
   Change Activity:
                   2020/5/1:
-------------------------------------------------
"""
import time

import cv2

import ml
from config.default_config import camera_config


def fetch_image_from_camera():
    url_list = camera_config['camera_address']
    for url in url_list:
        ml.logger.info(rf'尝试连接摄像头:{url}')
        cap = cv2.VideoCapture(url)
        start_time = time.time()
        ret, frame = cap.read()
        if frame is None:
            ml.logger.error(rf'连接摄像头失败{url}')
            return None
        ml.logger.info(rf"读取摄像头成功，耗时{time.time() - start_time}")
        cap.release()


if __name__ == '__main__':
    fetch_image_from_camera()
